<?php
/*
	
$cuid=$_POST['CUID'];
$password=$_POST['password1'];
$fname=$_POST['firstName'];
$mname=$_POST['middleName'];
$lname=$_POST['lastName'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipcode=$_POST['zipCode'];
$cellnumber=$_POST['cellNumber'];
$sex=$_POST['sex'];
$deptid=$_POST['departmentName'];
$role='Student';

$periodofgraduation=$_POST['periodOfGraduation'];
$yeardofgraduation=$_POST['yearOfGraduation'];
$areaofinterest=$_POST['areaOfInterest'];
$courses=$_POST['Courses'];

$conn = oci_connect("gaurav", "gaurav", "xe"); 

$query = "INSERT INTO Candidate(CUID,Password,FName,MName,LName,Address1,Address2,City,State,Country,ZipCode,CellNumber,CreationDate,Sex,DeptID,Role,SelfImage) VALUES(:cuid,:password,:fname,:mname,:lname,:address1,:address2,:city,:state,:country,:zipcode,:cellnumber,SysDate,:sex,:deptid,:role,EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA)";

$query1 = "INSERT INTO Student(CUID,PeriodOfGraduation,YeardOfGraduation,AreaOfInterest,Course) VALUES(:cuid,:periodofgraduation,:yeardofgraduation,:areaofinterest,:course)";

$bindargs1 = array();
array_push($bindargs1, array('CUID', $cuid, -1));
array_push($bindargs1, array('PERIODOFGRADUATION', $periodofgraduation, -1));
array_push($bindargs1, array('YEARDOFGRADUATION', $yeardofgraduation, -1));
array_push($bindargs1, array('AREAOFINTEREST', $areaofinterest, -1));
array_push($bindargs1, array('COURSE', $courses, -1));

//echo 'Message'.$cuid.$password1.$fname.$mname.$lname.$address1.$address2.$city.$state.$country.$zipcode.$cellnumber.$sex.$deptid.$role;



$bindargs = array();
array_push($bindargs, array('CUID', $cuid, -1));
array_push($bindargs, array('PASSWORD', $password, -1));
array_push($bindargs, array('FNAME', $fname, -1));
array_push($bindargs, array('MNAME', $mname, -1));
array_push($bindargs, array('LNAME', $lname, -1));
array_push($bindargs, array('ADDRESS1', $address1, -1));
array_push($bindargs, array('ADDRESS2', $address2, -1));
array_push($bindargs, array('CITY', $city, -1));
array_push($bindargs, array('STATE', $state, -1));
array_push($bindargs, array('COUNTRY', $country, -1));
array_push($bindargs, array('ZIPCODE', $zipcode, -1));
array_push($bindargs, array('CELLNUMBER', $cellnumber, -1));
array_push($bindargs, array('SEX', $sex, -1));
array_push($bindargs, array('DEPTID', $deptid, -1));
array_push($bindargs, array('ROLE', $role, -1));



$r = db_execute_statement($conn, $query, $bindargs);
$r1 = db_execute_statement($conn, $query1, $bindargs1);


//header('Location: /ViewAllStudents.php');

function db_execute_statement($conn, $statement,&$e, $bindvars = array())
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }
    // Bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value 
    $$b[0] = $b[1];
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]);
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }

  $r = oci_execute($stid);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
  $outbinds = array();
  foreach ($bindvars as $b) {
    $outbinds[$b[0]] = $$b[0];
  }
   $bindvars = $outbinds;
  return($r);
}

*/

$caption='hola!';
$albumid='6';
$cuiid = 'gip2103';

//echo 'Message'.$_POST['CUID'];

$conn = oci_connect("gaurav", "gaurav", "xe"); 
$lob = oci_new_descriptor($conn, OCI_D_LOB);
//$stmt = oci_parse($conn, 'INSERT INTO PHOTOS (PHOTOID, IMAGE, CAPTION, ALBUMID, CreationDate) VALUES(photosseq.nextval, EMPTY_BLOB(), :caption, :albumid, SysDate) RETURNING IMAGE INTO :IMAGE');
$stmt = oci_parse($conn, 'UPDATE CANDIDATE SET SELFIMAGE = EMPTY_BLOB() WHERE CUID = :cuiid RETURNING SELFIMAGE INTO :SELFIMAGE');
          //oci_bind_by_name($stmt, ':CAPTION', $caption);
		  //oci_bind_by_name($stmt, ':ALBUMID', $albumid);
		  oci_bind_by_name($stmt, ':SELFIMAGE', $lob, -1, OCI_B_BLOB);
		  oci_bind_by_name($stmt, ':CUIID', $cuiid);
          oci_execute($stmt, OCI_DEFAULT);

          // The function $lob->savefile(...) reads from the uploaded file.
          // If the data was already in a PHP variable $myv, the
          // $lob->save($myv) function could be used instead.
          if ($lob->savefile($_FILES['empphoto']['tmp_name'])) 
		  {
            oci_commit($conn);
          }
          else {
            echo "Couldn't upload Blob\n";
          }
          $lob->free();
          oci_free_statement($stmt);
		  
?>